<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\controller\v1;

use app\api\service\Token as TokenService;
use app\api\service\UserToken;
use app\api\validate\CodeValidate;
use app\lib\exception\TokenException;

/**
 * Token
 * Class Token
 * @package app\api\controller\v1
 */
class Token extends BaseController
{
    public function getToken($code = '')
    {
        (new CodeValidate())->goCheck();
        return (new UserToken($code))->get();
    }

    public function verifyToken($token = '')
    {
        if (!$token) {
            throw new TokenException([
                'message'   => 'token不允许为空',
                'errorCode' => 10004,
            ]);
        }
        return TokenService::verifyTokenValidity($token);
    }
}